<template>
  <el-dialog
    title="奖金发起"
    :close-on-click-modal="false"
    :visible.sync="visible"
    width="70vw"
    top="8vh"
    append-to-body
  >
    <el-form
      :model="dataForm"
      :key="isRef"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="130px"
      style="height: 58vh; overflow-y: auto"
    >
      <div class="boxsty">
        <el-row>
          <el-col :span="16">
            <el-form-item label="负责部门" prop="jjDeptId">
              <el-select
                v-model="dataForm.jjDeptId"
                placeholder="请选择负责部门"
                class="xiaLa"
                style="width: 100%"
                :clearable="true"
                @change="switchDepartment"
                :disabled="xgBz"
              >
                <el-option
                  v-for="(item, index) in fzbmData"
                  :key="index"
                  :label="item.deptName"
                  :value="item.deptId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <div v-if="dataForm.loginUserId == dataForm.createUserId">
              <el-form-item
                label="允许无总额分配"
                prop="sfNototal"
                label-width="170px"
              >
                <template slot-scope="scope">
                  <el-radio v-model="dataForm.sfNototal" label="是"
                    >是</el-radio
                  >
                  <el-radio v-model="dataForm.sfNototal" label="否"
                    >否</el-radio
                  >
                </template>
              </el-form-item>
            </div>
            <div v-else>
              <el-form-item
                label="允许无总额分配"
                prop="sfNototal"
                label-width="170px"
              >
                <template slot-scope="scope">
                  <el-radio v-model="dataForm.sfNototal" label="是" disabled
                    >是</el-radio
                  >
                  <el-radio v-model="dataForm.sfNototal" label="否" disabled
                    >否</el-radio
                  >
                </template>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row>

          <el-col
            :span="8"
            v-if="dataForm.sfCeff == '是' && dataForm.sfNototal == '否'"
          >
            <el-form-item label="超额发放率">
              <el-input-number
                v-model="dataForm.distrPerce"
                placeholder="%"
                style="width: 90%"
                :min="1"
                :max="100"
              ></el-input-number
              >%
            </el-form-item>
          </el-col>
          <el-col
            :span="8"
            v-if="dataForm.sfCeff == '是' && dataForm.sfNototal == '否'"
          >
            <el-form-item label="超额发放分类" prop="distrMe">
              <el-select
                v-model="dataForm.distrMe"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option value="1" label="按总额"></el-option>
                <el-option value="2" label="按月总额"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="dataForm.sfNototal == '否'">
            <el-form-item
              label="允许超额发放"
              prop="sfCeff"
              label-width="170px"
            >
              <el-radio v-model="dataForm.sfCeff" label="是">是</el-radio>
              <el-radio v-model="dataForm.sfCeff" label="否">否</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="奖金名称" prop="jjMc">
              <el-input
                v-model="dataForm.jjMc"
                placeholder="奖金名称"
              ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="奖金类型" prop="jjLx">
              <el-select
                v-model="dataForm.jjLx"
                placeholder="请选择"
                style="width: 100%"
              >
                <el-option value="1" label="年度"></el-option>
                <!--                <el-option value="2" label="月度"></el-option>-->
                <el-option value="3" label="日常"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item
              label="允许进入奖金池"
              prop="sfPripool"
              label-width="170px"
            >
              <el-radio v-model="dataForm.sfPripool" label="是">是</el-radio>
              <el-radio v-model="dataForm.sfPripool" label="否">否</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="开始日期" prop="jjDateq">
              <el-date-picker
                v-model="dataForm.jjDateq"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="开始日期"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="结束日期" prop="jjDatez">
              <el-date-picker
                v-model="dataForm.jjDatez"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="结束日期"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="dataForm.sfPripool=='是'">
            <el-form-item label="过期时间" prop="gqTime">
              <el-date-picker
                v-model="dataForm.gqTime"
                type="date"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="过期时间"
                style="width: 100%"
                :disabled="dataForm.sfPripool != '是'"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="分配来源" prop="fpLy">
              <el-select
                v-model="dataForm.fpLy"
                placeholder="请选择"
                style="width: 100%"
                @change="followUpfp"
                :disabled="xgBz"
              >
                <el-option value="1" label="上级分配"></el-option>
                <el-option value="2" label="单位自筹"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="奖金总额" prop="jjZe">
              <el-input-number
                v-model="dataForm.jjZe"
                @blur="isShu"
                :min="0"
                :max="1000000000"
                :precision="2"
                :step="1"
                label="奖金总额"
                style="width: 90%"
                :disabled="
                  dataForm.sfNototal == '是' ||
                  dataForm.loginUserId != dataForm.createUserId
                "
              ></el-input-number>
              元
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="奖金池">
              <el-select
                v-model="dataForm.jjBh"
                placeholder="请选择"
                style="width: 100%"
                :disabled="dataForm.fpLy == 2"
                @change="followUpjj"
                multiple
              >
                <el-option
                  v-for="(item, j) in jjData"
                  :key="j"
                  :label="machining(item)"
                  :value="item.jjcId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </div>
      <el-divider v-if="dataForm.dataList.length > 0"></el-divider>
      <el-row v-for="(item, index) in dataForm.dataList" :key="index">
        <el-col :span="7">
          <el-form-item
            label="奖金项名称"
            :prop="'dataList[' + index + '].jjxId'"
            :rules="[
              {
                required: true,
                message: '奖金项名称不能为空',
                trigger: 'blur',
              },
            ]"
          >
            <el-select
              v-model="dataForm.dataList[index].jjxId"
              clearable
              placeholder="请选择奖金项"
              style="width: 100%"
              @change="jjxHandle(index)"
              :disabled="
                dataForm.dataList[index].id != '' &&
                dataForm.loginUserId != dataForm.createUserId
              "
            >
              <!-- :disabled="dataForm.dataList[index].id != undefined" -->
              <el-option
                v-for="itema in cityHandle()"
                :key="itema.id"
                :label="itema.jjxMc"
                :value="itema.id"
                :disabled="itema.disabled"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item
            label="奖金项金额"
            :prop="'dataList[' + index + '].jjJe'"
            :rules="[
              {
                required: true,
                message: '奖金项金额不能为空',
                trigger: 'blur',
              },
            ]"
          >
            <el-input-number
              v-model="dataForm.dataList[index].jjJe"
              :min="0"
              :max="1000000000"
              :precision="2"
              :step="1"
              label="奖金项金额"
              style="width: 90%"
              @change="jjxZehj"
            ></el-input-number>
            元
            <!-- :disabled="dataForm.dataList[index].id != undefined" -->
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item
            label="奖金项日期"
            :prop="'dataList[' + index + '].jjxRq'"
            :rules="[
              {
                required: true,
                message: '奖金项日期不能为空',
                trigger: 'blur',
              },
            ]"
          >
            <!-- <el-input v-model="dataForm.dataList[index].jjxRq" placeholder="请输入奖金项日期" style="width:100%;"
                      @change="jjxudpate(item)"></el-input> -->
            <el-date-picker
              v-model="dataForm.dataList[index].jjxRq"
              @change="jjxudpate(item)"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="奖金项日期"
              style="width: 100%"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-button
            @click="removeItem(index)"
            v-if="
              (dataForm.dataList.length > 1 &&
                dataForm.dataList[index].id == '') ||
              dataForm.loginUserId == dataForm.createUserId
            "
            style="right: 5px"
            class="ml10"
            icon="el-icon-minus"
          ></el-button>
          <el-button
            @click="addItem()"
            v-if="index == dataForm.dataList.length - 1"
            icon="el-icon-plus"
            class="ml10"
          ></el-button>
        </el-col>
        <el-col :span="8" class="ml30" style="float: right">
          <div v-if="dataForm.loginUserId == dataForm.createUserId">
            <el-form-item
              label="是否允许预留"
              :prop="'dataList[' + index + '].sfZx'"
            >
              <el-radio v-model="dataForm.dataList[index].sfZx" label="是"
                >是</el-radio
              >
              <el-radio v-model="dataForm.dataList[index].sfZx" label="否"
                >否</el-radio
              >
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit"
        >确定</el-button
      >
      <el-button type="primary" plain @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { addObj, getObj, updateById } from "@/api/jiangjin/jiangjinfpjjfpdjb";
import { getFplyList } from "@/api/jiangjin/jiangjinfpjjlydjb";
import { getJjDeptJjx } from "@/api/jiangjin/jiangjinjjxxxb";
import { getJiangJinBm } from "@/api/admin/dept";

export default {
  data() {
    return {
      xgBz: false,
      visible: false,
      canSubmit: false,
      cityOptions: [],
      jjData: [], //奖金池
      jjxList: [], //奖金项list
      fzbmData: [],
      dataForm: {
        id: 0,
        jjDeptId: "",
        jjDeptName: "",
        sfZx: "",
        sfCeff: "",
        jjLx: "",
        fpLy: "",
        gqTime: new Date(new Date().getFullYear() + "-12-31 23:59:59"),
        jjBh: "",
        jjMc: "",
        jjDateq: "",
        jjDatez: "",
        jjZe: "",
        dataList: [],
        jjZelin: 0,
        isShuCheck: false,
        sfNototal: "否",
        sfPripool: "",
        distrPerce: "",
        distrMe: "",
      },
      isRef: false,
      dataRule: {
        jjDeptId: [
          { required: true, message: "请选择负责部门", trigger: "blur" },
        ],
        sfNototal: [
          {
            required: true,
            message: "是否允许无总额分配不能为空",
            trigger: "blur",
          },
        ],
        sfCeff: [
          {
            required: true,
            message: "是否允许超额发放不能为空",
            trigger: "blur",
          },
        ],
        // distrPerce:[
        //   {required: true, message: '超额发放百分比不能为空', trigger: 'blur'}
        // ],
        distrMe: [
          { required: true, message: "超额发放分类不能为空", trigger: "blur" },
        ],
        sfZx: [
          { required: true, message: "是否允许预留不能为空", trigger: "blur" },
        ],
        jjLx: [{ required: true, message: "请选择奖金类型", trigger: "blur" }],
        fpLy: [{ required: true, message: "请选择分配来源", trigger: "blur" }],
        gqTime: [
          { required: true, message: "过期时间不能为空", trigger: "blur" },
        ],
        jjBh: [{ required: true, message: "请选择奖金池", trigger: "blur" }],
        jjMc: [
          { required: true, message: "奖金名称不能为空", trigger: "blur" },
        ],
        jjDateq: [
          { required: true, message: "开始日期不能为空", trigger: "blur" },
        ],
        jjDatez: [
          { required: true, message: "结束日期不能为空", trigger: "blur" },
        ],
      },
      isJiangZ: false,
      isAdd: true,
      jjcZye: 0,
    };
  },
  watch: {
    "dataForm.sfZx": {
      handler(newName, oldName) {
        ////console.log(newName, oldName);
        if (newName == "否") {
          this.dataForm.gqTime = new Date(
            new Date().getFullYear() + "-12-31 23:59:59"
          );
        }
      },
      immediate: true,
      // deep: true
    },
  },
  methods: {
    //是否点击了金额输入框
    isShu() {
      this.isShuCheck = true;
    },
    //奖金项总额合计
    jjxZehj() {
      //console.log("this.dataForm.jjZe："+this.dataForm.jjZe)
      //this.isShuCheck  dataForm.sfNototal
      if (this.dataForm.sfNototal == "否") {
        this.dataForm.jjZelin = 0;
        var zongE = 0;
        for (var a in this.dataForm.dataList) {
          this.dataForm.jjZelin =
            this.dataForm.jjZelin +
            (this.dataForm.dataList[a].jjJe == undefined
              ? 0
              : this.dataForm.dataList[a].jjJe);
          if (
            this.dataForm.sfCeff == "是" &&
            this.dataForm.distrPerce * 1 > 0
          ) {
            zongE =
              (this.dataForm.jjZe * 1 + this.jjcZye * 1) *
              (1 + (this.dataForm.distrPerce * 1) / 100);
            if (this.dataForm.jjZelin * 1 > zongE) {
              this.dataForm.dataList[a].jjJe = 0;
              this.$message.closeAll()
              this.$message.warning("奖金项金额总和大于奖金总额");
              //console.log(this.dataForm.dataList[a].jjJe)
              this.isRef = !this.isRef;
              this.$forceUpdate();
            }
          }
          if (
            this.dataForm.sfCeff == "是" &&
            this.dataForm.distrPerce * 1 == 0
          ) {
            this.dataForm.jjZe = 0;
            this.dataForm.jjZe =
              this.dataForm.jjZe +
              (this.dataForm.dataList[a].jjJe == undefined
                ? 0
                : this.dataForm.dataList[a].jjJe);
          }
          if (this.dataForm.sfCeff == "否") {
            if (
              this.dataForm.jjZelin * 1 >
              this.dataForm.jjZe * 1 + this.jjcZye * 1
            ) {
              this.dataForm.dataList[a].jjJe = 0;
              this.$message.closeAll()
              this.$message.warning("奖金项金额总和大于奖金总额");
              //console.log(this.dataForm.dataList[a].jjJe)
              this.isRef = !this.isRef;
              this.$forceUpdate();
            }
          }
        }
      } else {
        this.dataForm.jjZe = 0;
        for (var a in this.dataForm.dataList) {
          this.dataForm.jjZe =
            this.dataForm.jjZe +
            (this.dataForm.dataList[a].jjJe == undefined
              ? 0
              : this.dataForm.dataList[a].jjJe);
        }
      }
    },
    //奖金项数据处理
    jjxHandle(index) {
      for (var a in this.cityOptions) {
        if (this.cityOptions[a].id == this.dataForm.dataList[index].jjxId) {
          this.dataForm.dataList[index].jjxMc = this.cityOptions[a].jjxMc;
          break;
        }
      }
    },
    //奖金项下拉处理
    cityHandle() {
      for (var b in this.cityOptions) {
        this.cityOptions[b].disabled = false;
        for (var a in this.dataForm.dataList) {
          if (this.dataForm.dataList[a].jjxId == this.cityOptions[b].id) {
            this.cityOptions[b].disabled = true;
          }
        }
      }

      return this.cityOptions;
    },
    //奖金点击事件
    followUpjj(value) {
      this.jjxList = [];
      this.dataForm.dataList = [];
      this.jjcZye = 0;
      for (var a in value) {
        for (var b in this.jjData) {
          if (value[a] == this.jjData[b].jjcId) {
            this.jjxList.push({
              id: this.jjData[b].jjcId,
              jjxId: this.jjData[b].jjxId,
              jjxMc: this.jjData[b].jjxName,
              jjJe: this.jjData[b].jjcYe,
              jjxRq: "",
              sfZx: "否",
            });
            this.jjcZye = this.jjcZye * 1 + this.jjData[b].jjcYe * 1;
          }
        }
      }
      console.log("this.jjcZye：" + this.jjcZye);
      var map = new Map();
      for (var c in this.jjxList) {
        if (!map.has(this.jjxList[c].jjxId)) {
          map.set(this.jjxList[c].jjxId, {
            id: this.jjxList[c].id,
            jjxId: this.jjxList[c].jjxId,
            jjxMc: this.jjxList[c].jjxName,
            jjJe: this.jjxList[c].jjcYe,
            jjxRq: "",
            sfZx: this.jjxList[c].sfZx,
          });
        } else {
          var jjcYe = map.get(this.jjxList[c].jjxId).jjcYe;
          map.set(this.jjxList[c].jjxId, {
            id: this.jjxList[c].id,
            jjxId: this.jjxList[c].jjxId,
            jjxMc: this.jjxList[c].jjxName,
            jjJe: this.jjxList[c].jjcYe + jjcYe,
            jjxRq: "",
            sfZx: this.jjxList[c].sfZx,
          });
        }
      }

      this.dataForm.dataList = [...map.values()];
      this.jjxZehj();
    },
    //奖金项日期批量修改
    jjxudpate(item) {
      for (var a in this.jjxList) {
        if (this.jjxList[a].jjxId == item.jjxId) {
          this.jjxList[a].jjxRq = item.jjxRq;
        }
      }
    },
    //奖金池下拉name数据加工
    machining(item) {
      return item.jjxName + "-" + item.jjxFl + "(" + item.jjcYe + "元)";
    },
    //分配点击事件
    followUpfp(value) {
      //1奖金池 2单位自筹
      this.dataForm.jjZe = 0;
      this.dataForm.jjBh = "";
      if (value == "2") {
        this.dataForm.dataList = [
          {
            jjxId: "",
            jjxMc: "",
            jjJe: 0,
            jjxRq: "",
            sfZx: "否",
            id: "",
          },
        ];
      } else if (value == "1") {
        this.dataForm.dataList = [];
      }
    },
    //添加数据项
    addItem() {
      this.dataForm.dataList.push({
        jjxId: "",
        jjxMc: "",
        jjJe: 0,
        jjxRq: "",
        sfZx: "否",
        id: "",
      });
    },
    //移除数据项
    removeItem(index) {
      this.dataForm.dataList.splice(index, 1);
      this.jjxZehj();
    },
    //初始化
    csh() {
      this.xgBz = false;
      this.jjxList = [];
      this.jjData = [];
      this.cityOptions = [];
      this.isShuCheck = false;
      this.dataForm = {
        id: 0,
        jjDeptId: "",
        jjDeptName: "",
        sfZx: "否",
        sfCeff: "否",
        jjLx: "",
        fpLy: "",
        gqTime: new Date(new Date().getFullYear() + "-12-31 23:59:59"),
        jjBh: "",
        jjMc: "",
        jjDateq: "",
        jjDatez: "",
        jjZe: "",
        dataList: [],
        jjZelin: 0,
        sfNototal: "否",
        sfPripool: "否",
        distrPerce: "",
        distrMe: "",
      };
    },
    init(id, text) {
      this.csh();
      this.dataForm.id = id || 0;
      if (text == "新增") {
        this.dataRule.jjBh[0].required = true;
      } else {
        this.dataRule.jjBh[0].required = false;
      }

      this.visible = true;
      this.canSubmit = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        getJiangJinBm().then((res) => {
          if (res.data.data.length > 0) {
            this.fzbmData = res.data.data;
          }
        });
        getFplyList(0).then((response) => {
          this.jjData = response.data.data;
        });
        if (this.dataForm.id) {
          getObj(this.dataForm.id).then((res) => {
            this.xgBz = true;
            this.dataForm = res.data.data;
            this.dataForm.jjLx = this.dataForm.jjLx + "";
            this.dataForm.fpLy = this.dataForm.fpLy + "";

            var jjxXq = JSON.parse(this.dataForm.jjxXq);
            //var jjxJeXq = JSON.parse(this.dataForm.jjxJeXq);
            var detailJson = JSON.parse(this.dataForm.detailJson);
            this.$set(this.dataForm, "dataList", []);
            console.log("奖金池detailJson:" + JSON.stringify(detailJson));
            for (var a in detailJson) {
              this.dataForm.dataList.push({
                jjxId: detailJson[a].jjxId,
                jjxMc: detailJson[a].jjxName,
                jjJe: detailJson[a].jjxJe,
                jjxRq: detailJson[a].jjxDate,
                sfZx: detailJson[a].sfZx,
                id: detailJson[a].id,
              });
            }
            getJjDeptJjx(this.dataForm.jjDeptId).then((res) => {
              this.cityOptions = res.data.data;
            });

            for (var a in this.fzbmData) {
              if (this.fzbmData[a].deptId == this.dataForm.jjDeptId) {
                this.dataForm.jjDeptId = this.fzbmData[a].deptId;
                this.dataForm.jjDeptName = this.fzbmData[a].deptName;
              }
            }
          });
        }
      });
    },
    switchDepartment(deptId) {
      this.csh();
      if (deptId != "") {
        getFplyList(deptId, 0).then((response) => {
          this.jjData = response.data.data;
          //console.log(JSON.stringify(response))
        });

        getJjDeptJjx(deptId).then((res) => {
          this.cityOptions = res.data.data;
        });

        for (var a in this.fzbmData) {
          if (this.fzbmData[a].deptId == deptId) {
            this.dataForm.jjDeptId = this.fzbmData[a].deptId;
            this.dataForm.jjDeptName = this.fzbmData[a].deptName;
          }
        }
      }
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate((valid) => {
        if (valid) {
          //结束大于等于开始
          if (this.dataForm.jjDatez < this.dataForm.jjDateq) {
            this.$notify.closeAll();
            this.$notify.error("结束时间应大于开始时间。");
            return;
          }

          // 过期大于结束
          if (this.dataForm.gqTime <= this.dataForm.jjDatez) {
            this.$notify.closeAll();
            this.$notify.error("过期时间应大于结束时间。");
            return;
          }

          var jjxXq = [];
          var jjxJeXq = {};
          for (var a in this.dataForm.dataList) {
            jjxXq.push({
              jjxId: this.dataForm.dataList[a].jjxId,
              jjxName: this.dataForm.dataList[a].jjxMc,
              jjxDate: this.dataForm.dataList[a].jjxRq,
              sfZx: this.dataForm.dataList[a].sfZx,
              id: this.dataForm.dataList[a].id,
            });

            this.$set(jjxJeXq, this.dataForm.dataList[a].jjxId, {
              fpJj: this.dataForm.dataList[a].jjJe,
              zjJj: 0,
              jjZe: this.dataForm.dataList[a].jjJe,
              bmJj: 0,
              ygJj: 0,
              dxFp: 0,
              jjYe: this.dataForm.dataList[a].jjJe,
              sfZx: this.dataForm.dataList[a].sfZx,
              id: this.dataForm.dataList[a].id,
            });
          }

          this.dataForm.jjxXq = JSON.stringify(jjxXq);
          this.dataForm.jjxJeXq = JSON.stringify(jjxJeXq);

          var data = {};
          if (this.dataForm.fpLy == "1") {
            //奖金池
            data = {
              fpxx: JSON.stringify(this.dataForm),
              lysyxx: JSON.stringify(this.jjxList),
            };
          } else if (this.dataForm.fpLy == "2") {
            //单位自筹
            data = {
              fpxx: JSON.stringify(this.dataForm),
              lysyxx: JSON.stringify(this.dataForm.dataList),
            };
          }

          this.canSubmit = false;
          if (this.dataForm.id) {
            updateById(data)
              .then((data) => {
                this.$notify.closeAll();
                this.$notify.success("修改成功");
                this.visible = false;
                this.$emit("refreshDataList");
              })
              .catch(() => {
                this.canSubmit = true;
              });
          } else {
            addObj(data)
              .then((data) => {
                this.$notify.closeAll();
                this.$notify.success("添加成功");
                this.visible = false;
                this.$emit("refreshDataList");
              })
              .catch(() => {
                this.canSubmit = true;
              });
          }
        }
      });
    },
  },
};
</script>
<style scoped>
.el-divider {
  background-color: #fff;
}
</style>
